package com.lkd.controller;

import com.lkd.dto.VmDto;
import com.lkd.vo.VmVo;
import com.lkd.entity.VmType;
import com.lkd.result.PageBean;
import com.lkd.result.Result;
import com.lkd.service.VmService;
import com.lkd.service.VmTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
//1、设备类型管理
public class VmTypeController extends Result {

    @Autowired
    private VmTypeService vmTypeService;
    @Autowired
    private VmService vmService;

    // 1.1 设备类型管理 设备搜索
    @GetMapping("/api/vm-service/vmType/search")
    public Result findByPage(VmDto dto) {
        PageBean<VmType> pageBean = vmTypeService.findByPage(dto);
        return success(pageBean);
    }

    // 1.1  设备搜索
    @GetMapping("/api/vm-service/vm/search")
    public Result findByKeyword(VmDto vmDto) {
        PageBean<VmVo> pageBean = vmService.findByPage(vmDto);
        return success(pageBean);
    }

    // 1.2 新增设备类型
    @PostMapping("/api/vm-service/vmType")
    public Result addVmType(@RequestBody VmType vmType) {
        Boolean result =vmTypeService.addVmType(vmType);
        return result ? success(result) : error("新增失败");
    }

    //1.3 修改设备类型
    @PutMapping("/api/vm-service/vmType")
    public Result updateVmType(@RequestBody VmType vmType) {
        Boolean result =vmTypeService.updateVmType(vmType);
        return result ? success(result) : error("修改失败");
    }

    //1.4 删除设备类型
    @DeleteMapping("/api/vm-service/vmType/{typeId}")
    public Result deleteVmType(@PathVariable("typeId") Integer typeId) {
        Boolean result =vmTypeService.deleteVmType(typeId);
        return result ? success(result) : error("删除失败");
    }



}
